package cn.autumnorange.app.common.repository.jpa;

import org.springframework.data.jpa.repository.support.JpaEntityInformation;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;

import javax.persistence.EntityManager;
import java.io.Serializable;

public class BaseJpaRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID>
    implements BaseJpaRepository<T, ID> {

  protected EntityManager entityManager;

  // 父类没有不带参数的构造方法，这里手动构造父类
  public BaseJpaRepositoryImpl(Class<T> domainClass, EntityManager entityManager) {
    super(domainClass, entityManager);
    this.entityManager = entityManager;
  }

  public BaseJpaRepositoryImpl(
      JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
    super(entityInformation, entityManager);
    this.entityManager = entityManager;
  }
  //
  //  // 通过EntityManager来完成查询
  //  @Override
  //  @Transactional
  //  public List<Object[]> listBySQL(String sql) {
  //    return entityManager.createNativeQuery(sql).getResultList();
  //  }
}
